package com.elminster.data.import0.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Component;

import com.elminster.data.import0.IDataImport;
import com.elminster.data.import0.ds.ExpensesDataStructure;
import com.elminster.util.CSVUtil;
import com.elminster.util.FileUtil;

@Component
public class ExpensesCsvImport implements IDataImport {

    public List<? extends Object> import0(String source) throws Exception {
        List<Object> list = new ArrayList<Object>();
        List<String> lines = FileUtil.readLines(source);
        
        if (null != lines) {
            for (String line : lines) {
                List<String> splited = CSVUtil.split(line);
                ExpensesDataStructure ds = new ExpensesDataStructure();
                ds.setDateStr(splited.get(1));
                ds.setLabel(splited.get(2));
                ds.setAmountStr(splited.get(3));
                list.add(ds);
            }
        }
        return list;
    }
}
